package indi.liangli.discovery;

import java.util.List;

public abstract class AbstractLoadBanlance  implements LoadBanlanceStrategy {


    /**
     * 改方法调用一个抽象方法，子类只需要关心业务的具体显实现，不用考虑数据为空等通用的做法
     * 命名selectHost，具体由子类实现的我们可以以do开头，真正做事的
     * @param serviceAddress 服务地址集合
     * @return
     */
    @Override
    public String selectHost(List<String> serviceAddress) {
        if(serviceAddress == null || serviceAddress.size() <= 0){
            return "";
        }
        if(serviceAddress.size() == 1){
            return serviceAddress.get(0);
        }
        //调用子类具体实现
        return doSelect(serviceAddress);
    }


    public abstract String doSelect(List<String> serviceAddress);

}
